﻿using System;
using System.Collections.Generic;

namespace Bookworm.Core
{
    internal static class FrameMappings
    {
        private static readonly Dictionary<string, FrameDetail> _mappings = new Dictionary<string, FrameDetail>(4);

        static FrameMappings()
        {
            Map<LanguageFrame>(FrameId.Language);
            Map<PublisherFrame>(FrameId.Publisher);
            Map<TitleFrame>(FrameId.Title);
            Map<DescriptionFrame>(FrameId.Description);
            Map<FormatFrame>(FrameId.Format);
            Map<CustomFormatFrame>(FrameId.CustomFormat);
            Map<RatingFrame>(FrameId.Rating);
            Map<Isbn10Frame>(FrameId.Isbn10);
            Map<Isbn13Frame>(FrameId.Isbn13);
            Map<PublishDateFrame>(FrameId.PublishDate);
            Map<PageCountFrame>(FrameId.PageCount);

            MapMultiple<TagFrame>(FrameId.Tag);
            MapMultiple<LinkFrame>(FrameId.Link);
            MapMultiple<ImageFrame>(FrameId.Image);
            MapMultiple<CategoryFrame>(FrameId.Category);
            MapMultiple<SubtitleFrame>(FrameId.SubTitle);
            MapMultiple<AuthorFrame>(FrameId.Author);
        }

        internal static Dictionary<string, FrameDetail> Mappings
        {
            get { return _mappings; }
        }

        private static void Map<TFrame>(string frameId)
        {
            _mappings.Add(frameId, new FrameDetail(typeof(TFrame), false));
        }

        private static void MapMultiple<TFrame>(string frameId)
        {
            _mappings.Add(frameId, new FrameDetail(typeof(TFrame), true));
        }
    }

    internal sealed class FrameDetail
    {
        private readonly Type _type;
        private readonly bool _allowMultiple;

        internal FrameDetail(Type type, bool allowMultiple)
        {
            _type = type;
            _allowMultiple = allowMultiple;
        }

        internal bool AllowMultiple
        {
            get { return _allowMultiple; }
        }

        internal Type Type
        {
            get { return _type; }
        }
    }
}
